import QtQuick
import music_player
import QtQuick.Controls
import "./view"

FramelessWindow {
    id: window
    width: 1100
    height: 750
    minimumHeight: 750
    minimumWidth: 1100
    visible: true
    title: qsTr("MusicPlayer")
    property string playSources: ''
    CommonDb {
        id: p_db
    }

    MusicContext {
        id: playContent
    }
    Rectangle {
        id: toast
        property string msg: ''
        width: toastText.contentWidth + 20
        height: toastText.contentHeight + 20
        color: "#e71e1d1d"
        opacity: msg === '' ? 0 : 1
        anchors.centerIn: parent
        radius: 5
        z: 10
        Behavior on opacity {
            NumberAnimation {}
        }
        Behavior on width {
            NumberAnimation {}
        }
        Behavior on height {
            NumberAnimation {}
        }

        Text {
            id: toastText
            anchors.centerIn: parent
            text: parent.msg
            color: "white"
        }
        function show(message) {
            msg = message;
            toastTimer.restart();
        }
        Timer {
            id: toastTimer
            interval: 1000
            onTriggered: {
                toast.msg = '';
            }
        }
    }
    QtObject {
        id: p_theme
        property int current: 0
        property var defaultTheme: [
            {
                "name": "primary",
                "backgroundColor": "#3f4241",
                "subBackgroundColor": "#4f4f4f",
                "fontColor": "#92bd6c",
                "subBackgroundColor2": "9dcb75",
                "type": "default"
            }
        ]
        function currentTheme() {
            return defaultTheme[current];
        }
        function changeTheme(theme) {
            defaultTheme.push(theme);
            current += 1;
        }
    }
    MusicResource {
        id: p_musicRes
    }

    // 计算窗口的位置使其居中显示
    Component.onCompleted: {
        var screenWidth = Screen.desktopAvailableWidth;
        var screenHeight = Screen.desktopAvailableHeight;
        var x = (screenWidth - width) / 2;
        var y = (screenHeight - height) / 2;
        window.x = x;
        window.y = y;
    }

    Column {
        anchors.fill: parent
        CTitleBar {
            id: titleBar
            width: parent.width
            height: 50
            color: "#3f4241"
        }
        Rectangle {
            id: content
            width: parent.width
            height: parent.height - titleBar.height - bottomBar.height
            Row {
                anchors.fill: parent
                CLeftContent {
                    id: leftContent
                    width: 180
                    height: parent.height
                }
                CRightContent {
                    id: rightContent
                    height: parent.height
                    width: parent.width - leftContent.width
                    qml: leftContent.contentQml()
                }
            }
        }
        CBottomBar {
            id: bottomBar
            height: 100
            width: parent.width
        }
    }
}
